<script setup lang="ts">
import Editor from "@/views/codegen/editor.vue";
import {useDialogPluginComponent, useQuasar} from "quasar";
import {GenCode} from "/wailsjs/go/api/GenerateApi";

defineEmits([
  // REQUIRED; 需要明确指出
  // 组件通过 useDialogPluginComponent() 暴露哪些事件
  ...useDialogPluginComponent.emits
])

const $q = useQuasar()

const {dialogRef, onDialogHide, onDialogOK, onDialogCancel} = useDialogPluginComponent()
const props = defineProps({
  title: {
    type: String,
  },
  keyx: {
    type: String,
  }
})

function onCodegen() {
  GenCode(props.keyx,props.title).then(res => {
    $q.notify({
      message: '生成成功',
    })
    onDialogCancel();
  })
}
</script>

<template>
  <q-dialog ref="dialogRef" maximized @hide="onDialogHide">
    <q-card class="">
      <q-bar class="bg-primary text-white" style="height: 35px">
        <div>{{ title }}</div>
        <q-space/>

        <q-btn dense flat icon="close" v-close-popup>
          <q-tooltip class="bg-white text-primary">关闭</q-tooltip>
        </q-btn>
      </q-bar>
      <div style="height: calc(100vh - 80px)">
        <Editor :keyx="keyx" dir="codegen"/>
      </div>
      <q-card-actions align="right" class="bg-grey-5">
        <q-btn size="sm" color="primary" @click="onCodegen">生成</q-btn>
      </q-card-actions>
    </q-card>
  </q-dialog>
</template>

<style scoped>

</style>
